import axios from 'axios';
import qs from 'qs';
if (process.env.NODE_ENV == 'development') {
  axios.defaults.baseURL = '/api';
} else if (process.env.NODE_ENV == 'debug') {
  axios.defaults.baseURL = '/api';
} else if (process.env.NODE_ENV == 'production') {
  axios.defaults.baseURL = '/api';
}
axios.defaults.baseURL = '/api'
axios.defaults.withCredentials = true
axios.defaults.crossDomain = true
// 设置默认请求头
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
export function get(url, params) {
  return new Promise((resolve, reject) => {
    axios.get(url, {
      params: params
    }).then(res => {
      resolve(res.data);
    }).catch(err => {
      reject(err.data)
    })
  });
}
export function post(url, params) {
  return new Promise((resolve, reject) => {
    axios.post(url, qs.stringify(params))
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        reject(err.data)
      })
  });
}
